package com.cailu.rabmq.sender.message;

import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;

/**
 * @author cailu
 * @filename ExpirationMessagePostProcessor
 * @description 延迟消费 设置消息的TTL属性
 * @date 2020/3/30 17:27
 */
public class ExpirationMessagePostProcessor implements MessagePostProcessor {

	// 毫秒
	private final Long ttl;

	public ExpirationMessagePostProcessor(Long ttl) {
		this.ttl = ttl;
	}


	@Override
	public Message postProcessMessage(Message message) throws AmqpException {
		message.getMessageProperties()
				// 设置per-message的失效时间
				.setExpiration(ttl.toString());
		return message;
	}
}
